const express=require('express');
const route=express.Router()
const md5=require('md5')
const adminModel=require("../db/model/adminModel");
const adminReg=require("../middleware/adminReg")
route.post('/addAdmin',adminReg,async function(req,res){
    const {
        adminName,
        password,
        regTime
    } = req.body
    console.log(adminName,password,regTime);
    try {
        const findResult = await adminModel.findOne({
            adminName,
        })
        if (findResult) {
           return res.send({
                code: 10001,
                msg: "添加管理员-用户已经被注册",
                data: null
            })
        }
        await adminModel.create({
            adminName,
            password:md5(password+"xyue"),
            regTime
        })
        res.send({
            code: 10000,
            msg: '添加管理员-添加成功',
            data: null
        })
    } catch (e) {
        console.log(e.message);
        res.send({
            code: 10002,
            msg: '添加管理员-服务端异常',
            data: null
        })
    }
})
module.exports=route